﻿using HardcoreGame.Content.Buffs;
using System;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace HardcoreGame.Common.Players
{
    public class ThirstPlayer : ModPlayer
    {
        public int CounterForThirst;
        public int StageForThirst = 1;
        public override void PostUpdate()
        {
            if (StageForThirst > 10)
            {
                StageForThirst = 10;
            }
            Player player = Main.player[Main.myPlayer];
            if (player.creativeGodMode)
            {
                StageForThirst = 1;
            }
            if (Math.Abs(player.velocity.X) > 0)
            {
                if (CounterForThirst > 0)
                {
                    if (player.ZoneJungle)
                    {
                        CounterForThirst -= 1 * 2;
                    }
                    else if (player.ZoneDesert)
                    {
                        CounterForThirst -= 1 * 33;
                    }
                    else
                    {
                        CounterForThirst--;
                    }
                }
                else if (CounterForThirst <= 0 && StageForThirst < 10)
                {
                    if (Main.masterMode)
                    {
                        CounterForThirst = 3530;
                    }
                    else
                    {
                        CounterForThirst = 5295;
                    }
                    StageForThirst += 1;
                }
            }
            if (StageForThirst >= 5)
            {
                player.AddBuff(ModContent.BuffType<Thirst>(), 2);
            }
            else
            {
                player.ClearBuff(ModContent.BuffType<Thirst>());
            }
        }
        public override void SaveData(TagCompound tag)
        {
            tag["CounterForThirst"] = CounterForThirst;
            tag["StageForThirst"] = StageForThirst;
        }
        public override void LoadData(TagCompound tag)
        {
            CounterForThirst = tag.GetInt("CounterForThirst");
            StageForThirst = tag.GetInt("StageForThirst");
        }
        public override void Kill(double damage, int hitDirection, bool pvp, PlayerDeathReason damageSource)
        {
            StageForThirst = 1;
            CounterForThirst = Main.masterMode ? 3530 * 2 : 5295 * 2;
        }
    }
}
